﻿using System.Windows.Controls;
using LogInModule.ViewModels;

namespace LogInModule.Views
{
    public partial class GameInit : UserControl
    {
        public GameInit( GameInitViewModel gameInitViewModel )
        {
            InitializeComponent();

            UserLogInViewModel userLogInViewModel = gameInitViewModel.container.Resolve<UserLogInViewModel>();
            userLogInViewModel.OnSuccessfulLogIn += () =>
            {
                this.Slideshow.OnNextClick();
            };
            this.userLogIn.Content = new UserLogInView( userLogInViewModel );

            this.DataContext = gameInitViewModel;

            this.gameModeSelection.GameModeSelected += ( mode ) =>
            {
                gameInitViewModel.GameMode = mode;
                this.Slideshow.OnNextClick();
            };

            this.characterSelection.CharacterSelected += ( character ) =>
            {
                gameInitViewModel.CharacterType = character;
                gameInitViewModel.Player.KidControlId = ( int )character;
                this.Slideshow.OnNextClick();
            };

            this.mapSelection.PlayGame += ( place ) =>
            {
                gameInitViewModel.Place = place;
                gameInitViewModel.OnPlayGame();
            };
        }

        public void Restart()
        {
            this.Slideshow.SelectedIndex = 0;
            this.Slideshow.SelectedItem = this.Slideshow.Items[0];
        }
    }
}
